require.config({
	 paths:{
	 	"jquery":"jquery",
	 	"common":"xz-common",
	 	"cookie":"jquery.cookie"
	 }
})
$pot=1;
$loginname = "";
require(["common","jquery","cookie"],function(common,$){
    
$(function(){ 

     //购物车跳转
    $("#xz-shopcar").mousedown(function(){
    	location.href = "../html/shopcar.html"
    	
    });
    //注册页跳转
    $("#toresgister").mousedown(function(){
    	location.href = "../html/register.html"
    
    });    
    //登录页跳转
     $("#xz-login").mousedown(function(){
    	location.href = "../html/login.html"
    	
    });	
    //列表页跳转
     $(".xz-listofgoods-one a").mousedown(function(){
     	location.href = "../html/listgoods.html"
     	
     });
     //是否登录
        if($.cookie("login")){
        	$("#xz-login").text($.cookie("login")+" ，点击重新登录");
        }else{
        	$("#xz-login").text("【登录】");
        }
     //退出
      $("#xz-login").mousedown(function(){
      	$.removeCookie("login",{expires:0,path:"/"});
      	location.href = "../html/login.html";
      })

   //对象转字符串
    function converObjToStr(obj){
    	var str = "";
    	for(var user in obj){
    		var pwd = obj[user]; 
    		if(str){
    			str +=":";
    		}
    		str += user +","+pwd;
    	}
    	return str;
    }
    
   //字符串转对象
	function converStrToObj(str){
		if(!str){
		return{};	
		}
		var arr = str.split(":");
		var obj={};
		for(var i= 0;i<arr.length;i++){
			var arr1 = arr[i].split(",");
			obj[arr1[0]] = arr1[1];
		}
		
		return obj;
	 }
		var str= converStrToObj( $.cookie("user")); 
		$(".xz-right-denglu input").mousedown(function(){
		if($(".xz-usrname").val() in str &&  str[$(".xz-usrname").val()]== $(".xz-loginpassword").val())
		{
			$("#login-error").css({"display":"none"});
		    alert("登录成功");
		    $.cookie("login",$(".xz-usrname").val(),{expires:7,path:"/"});
            window.open("../main.html");
		}
		else{
			$("#login-error").css({"display":"block"});
		}
		

		})
	})
	
})
